Implementing Type Classes using Type-Indexed Functions∗
نویسنده
چکیده
Type classes [19, 7] are, according to some authors, ‘the most beloved feature of Haskell’. They provide a clean, modular and elegant way of writing overloaded functions. Type classes are usually implemented using dictionaries—data structures containing functions and other dictionaries—which are passed as extra arguments to the overloaded functions. Thus, programs using type classes are translated into programs with dictionaries that are correct according to the DamasMilner type system. Functional logic programming (FLP) has inherited the Damas-Milner type system from its functional part, so it may seem that using the same translation for these languages is also a good option. However, this translation presents some problems in FLP because of an undesired excess of sharing that appears with non-determinism. In this paper we propose an alternative translation of type classes which uses type witnesses and type-indexed functions (in the sense of [11]) instead of dictionaries. The translated programs are correct according to a new simple extension of the Damas-Milner type system recently proposed for FLP [13]. Apart from solving the mentioned problem of undesired sharing, the proposed translation also obtains interesting efficiency results: in functional languages (GHC, Hugs) it can compete with the built-in translation, and in FLP (Toy, Curry) it obtains an important speedup—between 1.2 ∗This work has been partially supported by the Spanish projects TIN2008-06622-C03-01 and UCMBSCH-GR58/08-910502. and 2.5 in the experiments—compared to the classical translation.
منابع مشابه
Hermite-Hadamard Type Inequalities for MφA-Convex Functions
This article deals with the different classes of convexity and generalizations. Firstly, we reveal the new generalization of the definition of convexity that can reduce many order of convexity. We have showed features of algebra for this new convex function. Then after we have constituted Hermite-Hadamard type inequalities for this class of functions. Finally the identity has been revealed for ...
متن کاملClasses of admissible functions associated with certain integral operators applied to meromorphic functions
In the present paper, by making use of the differential subordination and superordination results of Miller and Mocanu, certain classes of admissible functions are determined so that subordination as well as superordination implications of functions associated with an integral operator hold. Additionally, differential sandwich-type result is obtained.
متن کاملWeak Convergence of Stationary Empirical Processes
We offer an umbrella type result which extends the convergence of classical empirical process on the line to more general processes indexed by functions of bounded variation. This extension is not contingent on the type of dependence of the underlying sequence of random variables. As a consequence we establish the weak convergence for stationary empirical processes indexed by general classes of...
متن کاملInstant Generics: Fast and Easy
This paper introduces a novel approach to datatype-generic programming based on type classes and type families. The approach favours simplicity as generic functions are based on Haskell’s standard construct for ad-hoc polymorphism, namely type classes — hence, it integrates well with existing classes and facilitates overriding of generic behaviour with conventional class instances. Moreover, ou...
متن کاملType Classes in Functional Logic Programming Author’s version for E-Prints Complutense
Type classes provide a clean, modular and elegant way of writing overloaded functions. Functional logic programming languages (FLP in short) like Toy or Curry have adopted the Damas-Milner type system, so it seems natural to adopt also type classes in FLP. However, type classes has been barely introduced in FLP. A reason for this lack of success is that the usual translation of type classes usi...
متن کامل